package map;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 遍历显示工资大于18000的员工信息
 * @date 2022/9/25 22:35
 */
public class MapExercise {

    public static void main(String[] args) {
        HashMap<Integer, Person> map = new HashMap<>(3);
        Person person1 = new Person("oyz", 100000, 1);
        Person person2 = new Person("oyl", 18000, 2);
        Person person3 = new Person("oyl", 10000, 3);
        map.put(1, person1);
        map.put(2, person2);
        map.put(3, person3);
        // 方法一

        Iterator<Integer> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            Person person = map.get(iterator.next());
            if (person.getSalary() >= 18000)
                System.out.println(person);
        }
        // 方法二
        Set<Integer> integers = map.keySet();
        for (Integer integer : integers) {
            Person person = map.get(integer);
            if (person.getSalary() >= 18000)
                System.out.println(person);
        }

    }

    static class Person {
        private String name;
        private Integer salary;
        private Integer id;

        public Person(String name, Integer salary, Integer id) {
            this.name = name;
            this.salary = salary;
            this.id = id;
        }


        public Integer getSalary() {
            return salary;
        }


        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", salary=" + salary +
                    ", id=" + id +
                    '}';
        }
    }
}
